//选项卡
(function($) {
	var CLASS_TAB = 'tab';
	var menuClassSelector = '.menu';
	var paneClassSelector = '.pane';

	var Tab = $.Tab = $.Class.extend({
		init: function(holder) {
			var self = this;
			if(!holder) {
				throw "构造 tab 时缺少容器元素";
			}
			self.holder = holder;
			self.menu = $.qsa(menuClassSelector, self.holder)[0];
			self.pane = $.qsa(paneClassSelector, self.holder)[0];
			self.initEvent();
		},
		initEvent: function() {
			var self = this;
			self.lis = self.menu.querySelectorAll('li');
			self.nodes = self.pane.querySelectorAll('.node');
			$(self.lis).each(function(i, element) {
				element.addEventListener('tap', function(event) {
					var target = this;
					$(self.lis).each(function(o, element) {
						if(element === target) {
							element.classList.add("active");
							self.nodes[o].classList.add("active");
						} else {
							element.classList.remove("active");
							self.nodes[o].classList.remove("active");
						}
					})

				});
			});

		}
	});

	$.fn.tab = function() {
		this.each(function(i, element) {
			if(element.tab) {
				return;
			}
			element.tab = new Tab(element);

		});
		return this[0] ? this[0].tab : null;
	}

	$.ready(function() {
		$('.' + CLASS_TAB).tab();
	});

})(mui);